<template>
    <div>
        <el-table border :data="adminData">
              <el-table-column label="用户名" prop="userName"> </el-table-column>
              <el-table-column label="姓名" prop="turename"> </el-table-column>
              <el-table-column label="手机" prop="phone"> </el-table-column>
              <el-table-column label="编辑日期">
                <template #default="scope">
                  <div>
                    {{new Date(scope.row.createAt).toLocaleString()}}
                  </div>
                </template>
              </el-table-column>
              <el-table-column label="权限">
                <template #default="scope">
                  <div> 
                      {{scope.row.power=="1"?'系统管理员':'课程管理员'}}
                  </div>
                </template>
              </el-table-column>
              <el-table-column label="操作">
                <template #default="scope">
                  <div>
                      <el-button @click="edit(scope.row)" type="primary">编辑</el-button>
                       <el-button @click="del(scope.row.tokenId)"  type="danger">删除</el-button>
                  </div>
                </template>
              </el-table-column>
        </el-table>
      <el-pagination @current-change="pageChange"  :page-size="3"  background layout="prev, pager, next" :total="count">
     </el-pagination>
    </div>
</template>

<script lang="ts">
export default {
  props:["adminData","count"],
}
</script>
<script lang="ts" setup>
import {delAdmin} from '../../api/admin'
import $bus from '../../utils/bus'
import {ref} from 'vue'
import { useStore } from 'vuex';

    //  defineEmits 定义要触发的事件
    const emit=defineEmits(["sendpagenum","senddata"])
    let page=ref(1);
    // 分页改变事件
    let pageChange=(val:number)=>{
        console.log(val)
        // 触发父组件的事件  并传页码
        emit("sendpagenum",val)
        page.value=val;//存储页码
    } 
    let del=async (id:number)=>{
      var res:any= await delAdmin(id)
      console.log(res)
         // 触发父组件的事件  
        emit("sendpagenum",page.value)
    }
    let store=useStore();
    // 点击编辑
    let edit=(row:any)=>{
        store.commit("changeAdminDia",true)
        $bus.emit("sendrow",row)
    }
</script>
<style lang="less">
      

</style>